<!DOCTYPE HTML>
<html>
<head>
    <title>站外商品导入</title>
    <link rel="stylesheet" href="/stylesheets/style.css">
    <script src="/scripts/jquery.min.js"></script>
    <link rel="stylesheet" href="/stylesheets/formdata.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">
    <script src="/scripts/miniui/miniui.js"></script>
</head>
<body>
<div class="container">
</div>
<div style="width:99%;text-align: center;">
    <div style="border-bottom:0;padding:20px;">
        <form id="form1" name="form1" method="post" action='/getdata/excelUpload' enctype="multipart/form-data" >
            <span style="width:80px;display:inline-block;padding-left: 30px">商品来源：</span>
            <input id="goodsSource" name="goodsSource" class="mini-combobox" style="width:155px;" data="goodsSourceData" value="0"/>
            <br/><br/>
            <span style="width:80px;display:inline-block;padding-left: 30px">商品分类：</span>
            <input id="btnSelectGoodsType" name="btnSelectGoodsType" class="mini-buttonedit" style="width:155px;" onbuttonclick="onButtonSelectGoodsType"/>
            <input id="pid" name="pid" class="mini-textbox" required="true" type="number" style="width:155px;display: none;" readonly="readonly"/>
            <br/><br/>
            <span style="width:80px;display:inline-block;padding-left: 30px">上传商品：</span>
            <input id="excelFile" name="excelFile" style="width:155px;" type="file" onchange="submit()"/>
            <div style="padding-top: 20px;">
                <a class="mini-button " iconCls="icon-ok" onclick="onOK">确定</a>
                <a class="mini-button" iconCls="icon-cancel" onclick="onCancel">取消</a>
            </div>
        </form>
    </div>
</div>
<div style="margin: 30px 0;text-align: center">

</div>
</body>
<script>
  var goodsSourceData = [{ id:0,text:'淘宝'},{id:1,text:'京东'}];
  mini.parse();
  function submit(){
    document.form1.submit()
  }
  function onOK(){
    let excelFile = document.getElementById("excelFile").value;
    if (excelFile.length < 1){
      alert('请选择要上传的文件!');
      return;
    }
    let data = {}
    let goodsSource = mini.get("goodsSource").getValue();
    if (goodsSource == 0){
      data.goodsSource = '淘宝'
    } else {
      data.goodsSource = '京东'
    }
    data.goodsTypeOId = mini.get("btnSelectGoodsType").getValue();
    data.goodsTypePId = mini.get("pid").getValue();
    if (!data.goodsTypeOId){
      alert('请选择商品分类!');
      return
    }
    mini.loading('请稍后,请不要重复操作！', '导入中...')
    $.ajax({
      type: "POST",
      url: "/getdata/importExternalGoods",
      data: data,
      success: function (result) {
        if (result) {
          CloseWindow("save");
        }else{
          alert("请填写正确数据");
        }
      }
    })
  }
  function onCancel(e) {
    CloseWindow("cancel");
  }
  //关闭窗口
  function CloseWindow(action) {
    if (action == "close" && form.isChanged()) {
      if (confirm("数据被修改了，是否先保存？")) {
        return false;
      }
    }
    if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
    else window.close();
  }
  function onButtonSelectGoodsType(e) {
    var btnSelectGoodsType = this;
    mini.open({
      url: "/getdata/shopIntergationSelectGoodsType",
      showMaxButton: false,
      title: "选择商品分类",
      width: 350,
      height: 350,
      ondestroy: function (action) {
        if (action == "ok") {
          var iframe = this.getIFrameEl();
          var data = iframe.contentWindow.GetData();
          data = mini.clone(data);
          if (data) {
            // console.log(data)
            btnSelectGoodsType.setValue(data.id);
            btnSelectGoodsType.setText(data.text);
            mini.get('pid').setValue(data.pid);
          }
        }
      }
    });
  }
</script>
</html>